
//
//  MCChooseForPlatformCell.swift
//  StoreManage
//
//  Created by MC on 2018/2/5.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCAddTicketChooseGoodsOrBrandCell: UITableViewCell {
    
    var model : MCAddTicketChooseGoodsOrBrandModel = MCAddTicketChooseGoodsOrBrandModel() {
        didSet {
            if model.goodsId <= 0 {
                iconImageView.sd_setImage(with: URL.init(string: model.logoPath), placeholderImage: #imageLiteral(resourceName: "Reuse_placeholder_1_1"))
                nameLabel.text = model.brandName
            } else {
                iconImageView.sd_setImage(with: URL.init(string: model.goodsImage), placeholderImage: #imageLiteral(resourceName: "Reuse_placeholder_1_1"))
                nameLabel.text = model.goodsName
            }
        }
    }
    
    var currentId : Int = 0 {
        didSet {
            if currentId == model.goodsId || currentId == model.brandId {
                statusImageView.isHidden = false
            } else {
                statusImageView.isHidden = true
            }
        }
    }
    
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        
        self.addSubview(iconImageView)
        iconImageView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.centerY.equalTo(self)
            make.size.equalTo(CGSize.init(width: 60, height: 60))
        }
        
        self.addSubview(nameLabel)
        nameLabel.snp.remakeConstraints { (make) ->Void in
            make.centerY.equalTo(self)
            make.left.equalTo(iconImageView.snp.right).offset(10)
            make.right.equalTo(-40)
        }

        
        self.addSubview(statusImageView)
        statusImageView.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(-10)
            make.centerY.equalTo(self)
            make.size.equalTo(CGSize.init(width: 20, height: 20))
        }
        
        self.addSubview(lineView)
        lineView.snp.remakeConstraints { (make) ->Void in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(1)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var iconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "Reuse_placeholder_1_1")
        imageView.layer.cornerRadius = 30
        imageView.layer.masksToBounds = true
        imageView.layer.borderColor = UIColor.MCGray_light.cgColor
        imageView.layer.borderWidth = 1
        return imageView
    }()

    
    lazy var statusImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "Reuse_selectedSign")
        imageView.isHidden = true
        return imageView
    }()
    
    
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.black
        label.font = MCFont(14)
        return label
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCGray_light
        return view
    }()
}


